{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = ts.get_stock_basics()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>industry</th>\n",
       "      <th>area</th>\n",
       "      <th>pe</th>\n",
       "      <th>outstanding</th>\n",
       "      <th>totals</th>\n",
       "      <th>totalAssets</th>\n",
       "      <th>liquidAssets</th>\n",
       "      <th>fixedAssets</th>\n",
       "      <th>reserved</th>\n",
       "      <th>...</th>\n",
       "      <th>bvps</th>\n",
       "      <th>pb</th>\n",
       "      <th>timeToMarket</th>\n",
       "      <th>undp</th>\n",
       "      <th>perundp</th>\n",
       "      <th>rev</th>\n",
       "      <th>profit</th>\n",
       "      <th>gpr</th>\n",
       "      <th>npr</th>\n",
       "      <th>holders</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>002959</th>\n",
       "      <td>N小熊</td>\n",
       "      <td>家用电器</td>\n",
       "      <td>广东</td>\n",
       "      <td>23.16</td>\n",
       "      <td>0.30</td>\n",
       "      <td>1.20</td>\n",
       "      <td>11.89</td>\n",
       "      <td>7.75</td>\n",
       "      <td>1.19</td>\n",
       "      <td>0.63</td>\n",
       "      <td>...</td>\n",
       "      <td>12.70</td>\n",
       "      <td>3.88</td>\n",
       "      <td>20190823</td>\n",
       "      <td>4.12</td>\n",
       "      <td>3.43</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>36.00</td>\n",
       "      <td>10.75</td>\n",
       "      <td>60075.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>300110</th>\n",
       "      <td>华仁药业</td>\n",
       "      <td>化学制药</td>\n",
       "      <td>山东</td>\n",
       "      <td>261.97</td>\n",
       "      <td>11.78</td>\n",
       "      <td>11.82</td>\n",
       "      <td>30.53</td>\n",
       "      <td>15.50</td>\n",
       "      <td>12.32</td>\n",
       "      <td>5.28</td>\n",
       "      <td>...</td>\n",
       "      <td>1.85</td>\n",
       "      <td>2.35</td>\n",
       "      <td>20100825</td>\n",
       "      <td>4.18</td>\n",
       "      <td>0.35</td>\n",
       "      <td>3.03</td>\n",
       "      <td>116.59</td>\n",
       "      <td>56.69</td>\n",
       "      <td>1.47</td>\n",
       "      <td>49331.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002505</th>\n",
       "      <td>大康农业</td>\n",
       "      <td>农业综合</td>\n",
       "      <td>湖南</td>\n",
       "      <td>95.52</td>\n",
       "      <td>54.85</td>\n",
       "      <td>54.85</td>\n",
       "      <td>162.92</td>\n",
       "      <td>88.15</td>\n",
       "      <td>28.74</td>\n",
       "      <td>2.54</td>\n",
       "      <td>...</td>\n",
       "      <td>0.84</td>\n",
       "      <td>2.06</td>\n",
       "      <td>20101118</td>\n",
       "      <td>-7.47</td>\n",
       "      <td>-0.14</td>\n",
       "      <td>-4.64</td>\n",
       "      <td>35.05</td>\n",
       "      <td>8.41</td>\n",
       "      <td>0.72</td>\n",
       "      <td>138483.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002121</th>\n",
       "      <td>科陆电子</td>\n",
       "      <td>电器仪表</td>\n",
       "      <td>深圳</td>\n",
       "      <td>0.00</td>\n",
       "      <td>9.29</td>\n",
       "      <td>14.08</td>\n",
       "      <td>118.67</td>\n",
       "      <td>61.50</td>\n",
       "      <td>27.51</td>\n",
       "      <td>19.04</td>\n",
       "      <td>...</td>\n",
       "      <td>2.43</td>\n",
       "      <td>2.24</td>\n",
       "      <td>20070306</td>\n",
       "      <td>-0.30</td>\n",
       "      <td>-0.02</td>\n",
       "      <td>-23.09</td>\n",
       "      <td>-219.97</td>\n",
       "      <td>28.05</td>\n",
       "      <td>-5.11</td>\n",
       "      <td>69768.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002337</th>\n",
       "      <td>赛象科技</td>\n",
       "      <td>化工机械</td>\n",
       "      <td>天津</td>\n",
       "      <td>0.00</td>\n",
       "      <td>5.88</td>\n",
       "      <td>5.89</td>\n",
       "      <td>15.44</td>\n",
       "      <td>11.80</td>\n",
       "      <td>2.12</td>\n",
       "      <td>4.25</td>\n",
       "      <td>...</td>\n",
       "      <td>2.02</td>\n",
       "      <td>2.00</td>\n",
       "      <td>20100115</td>\n",
       "      <td>1.07</td>\n",
       "      <td>0.18</td>\n",
       "      <td>-51.88</td>\n",
       "      <td>-65.01</td>\n",
       "      <td>29.51</td>\n",
       "      <td>-56.06</td>\n",
       "      <td>77476.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 22 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        name industry area      pe  outstanding  totals  totalAssets  \\\n",
       "code                                                                   \n",
       "002959   N小熊     家用电器   广东   23.16         0.30    1.20        11.89   \n",
       "300110  华仁药业     化学制药   山东  261.97        11.78   11.82        30.53   \n",
       "002505  大康农业     农业综合   湖南   95.52        54.85   54.85       162.92   \n",
       "002121  科陆电子     电器仪表   深圳    0.00         9.29   14.08       118.67   \n",
       "002337  赛象科技     化工机械   天津    0.00         5.88    5.89        15.44   \n",
       "\n",
       "        liquidAssets  fixedAssets  reserved  ...   bvps    pb  timeToMarket  \\\n",
       "code                                         ...                              \n",
       "002959          7.75         1.19      0.63  ...  12.70  3.88      20190823   \n",
       "300110         15.50        12.32      5.28  ...   1.85  2.35      20100825   \n",
       "002505         88.15        28.74      2.54  ...   0.84  2.06      20101118   \n",
       "002121         61.50        27.51     19.04  ...   2.43  2.24      20070306   \n",
       "002337         11.80         2.12      4.25  ...   2.02  2.00      20100115   \n",
       "\n",
       "        undp  perundp    rev  profit    gpr    npr   holders  \n",
       "code                                                          \n",
       "002959  4.12     3.43   0.00    0.00  36.00  10.75   60075.0  \n",
       "300110  4.18     0.35   3.03  116.59  56.69   1.47   49331.0  \n",
       "002505 -7.47    -0.14  -4.64   35.05   8.41   0.72  138483.0  \n",
       "002121 -0.30    -0.02 -23.09 -219.97  28.05  -5.11   69768.0  \n",
       "002337  1.07     0.18 -51.88  -65.01  29.51 -56.06   77476.0  \n",
       "\n",
       "[5 rows x 22 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "df=df.reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "df=df[df['code'].str.match('688.*?')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>name</th>\n",
       "      <th>industry</th>\n",
       "      <th>area</th>\n",
       "      <th>pe</th>\n",
       "      <th>outstanding</th>\n",
       "      <th>totals</th>\n",
       "      <th>totalAssets</th>\n",
       "      <th>liquidAssets</th>\n",
       "      <th>fixedAssets</th>\n",
       "      <th>...</th>\n",
       "      <th>bvps</th>\n",
       "      <th>pb</th>\n",
       "      <th>timeToMarket</th>\n",
       "      <th>undp</th>\n",
       "      <th>perundp</th>\n",
       "      <th>rev</th>\n",
       "      <th>profit</th>\n",
       "      <th>gpr</th>\n",
       "      <th>npr</th>\n",
       "      <th>holders</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>715</th>\n",
       "      <td>688010</td>\n",
       "      <td>福光股份</td>\n",
       "      <td>电器仪表</td>\n",
       "      <td>福建</td>\n",
       "      <td>122.40</td>\n",
       "      <td>0.35</td>\n",
       "      <td>1.54</td>\n",
       "      <td>9.95</td>\n",
       "      <td>4.36</td>\n",
       "      <td>2.43</td>\n",
       "      <td>...</td>\n",
       "      <td>11.30</td>\n",
       "      <td>6.53</td>\n",
       "      <td>20190722</td>\n",
       "      <td>3.16</td>\n",
       "      <td>2.06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>36.47</td>\n",
       "      <td>17.07</td>\n",
       "      <td>30737.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2265</th>\n",
       "      <td>688029</td>\n",
       "      <td>南微医学</td>\n",
       "      <td>医疗保健</td>\n",
       "      <td>江苏</td>\n",
       "      <td>53.74</td>\n",
       "      <td>0.31</td>\n",
       "      <td>1.33</td>\n",
       "      <td>10.90</td>\n",
       "      <td>7.14</td>\n",
       "      <td>1.38</td>\n",
       "      <td>...</td>\n",
       "      <td>17.42</td>\n",
       "      <td>6.95</td>\n",
       "      <td>20190722</td>\n",
       "      <td>3.34</td>\n",
       "      <td>2.51</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>65.86</td>\n",
       "      <td>24.31</td>\n",
       "      <td>27600.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2840</th>\n",
       "      <td>688321</td>\n",
       "      <td>微芯生物</td>\n",
       "      <td>化学制药</td>\n",
       "      <td>深圳</td>\n",
       "      <td>958.03</td>\n",
       "      <td>0.41</td>\n",
       "      <td>4.10</td>\n",
       "      <td>8.28</td>\n",
       "      <td>2.87</td>\n",
       "      <td>0.12</td>\n",
       "      <td>...</td>\n",
       "      <td>3.52</td>\n",
       "      <td>23.23</td>\n",
       "      <td>20190812</td>\n",
       "      <td>-0.22</td>\n",
       "      <td>-0.05</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>96.11</td>\n",
       "      <td>21.38</td>\n",
       "      <td>27993.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3339</th>\n",
       "      <td>688333</td>\n",
       "      <td>铂力特</td>\n",
       "      <td>机械基件</td>\n",
       "      <td>陕西</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.18</td>\n",
       "      <td>0.80</td>\n",
       "      <td>7.97</td>\n",
       "      <td>3.74</td>\n",
       "      <td>3.15</td>\n",
       "      <td>...</td>\n",
       "      <td>12.40</td>\n",
       "      <td>5.96</td>\n",
       "      <td>20190722</td>\n",
       "      <td>0.68</td>\n",
       "      <td>0.85</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>35.25</td>\n",
       "      <td>-2.18</td>\n",
       "      <td>13218.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3474</th>\n",
       "      <td>688009</td>\n",
       "      <td>中国通号</td>\n",
       "      <td>运输设备</td>\n",
       "      <td>北京</td>\n",
       "      <td>38.24</td>\n",
       "      <td>11.84</td>\n",
       "      <td>105.90</td>\n",
       "      <td>836.01</td>\n",
       "      <td>687.34</td>\n",
       "      <td>39.11</td>\n",
       "      <td>...</td>\n",
       "      <td>3.50</td>\n",
       "      <td>2.79</td>\n",
       "      <td>20190722</td>\n",
       "      <td>93.10</td>\n",
       "      <td>0.88</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.43</td>\n",
       "      <td>8.58</td>\n",
       "      <td>696322.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        code  name industry area      pe  outstanding  totals  totalAssets  \\\n",
       "715   688010  福光股份     电器仪表   福建  122.40         0.35    1.54         9.95   \n",
       "2265  688029  南微医学     医疗保健   江苏   53.74         0.31    1.33        10.90   \n",
       "2840  688321  微芯生物     化学制药   深圳  958.03         0.41    4.10         8.28   \n",
       "3339  688333   铂力特     机械基件   陕西    0.00         0.18    0.80         7.97   \n",
       "3474  688009  中国通号     运输设备   北京   38.24        11.84  105.90       836.01   \n",
       "\n",
       "      liquidAssets  fixedAssets  ...   bvps     pb  timeToMarket   undp  \\\n",
       "715           4.36         2.43  ...  11.30   6.53      20190722   3.16   \n",
       "2265          7.14         1.38  ...  17.42   6.95      20190722   3.34   \n",
       "2840          2.87         0.12  ...   3.52  23.23      20190812  -0.22   \n",
       "3339          3.74         3.15  ...  12.40   5.96      20190722   0.68   \n",
       "3474        687.34        39.11  ...   3.50   2.79      20190722  93.10   \n",
       "\n",
       "      perundp  rev  profit    gpr    npr   holders  \n",
       "715      2.06  0.0     0.0  36.47  17.07   30737.0  \n",
       "2265     2.51  0.0     0.0  65.86  24.31   27600.0  \n",
       "2840    -0.05  0.0     0.0  96.11  21.38   27993.0  \n",
       "3339     0.85  0.0     0.0  35.25  -2.18   13218.0  \n",
       "3474     0.88  0.0     0.0  24.43   8.58  696322.0  \n",
       "\n",
       "[5 rows x 23 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "上海     7\n",
       "北京     6\n",
       "江苏     4\n",
       "浙江     3\n",
       "陕西     2\n",
       "广东     2\n",
       "深圳     2\n",
       "黑龙江    1\n",
       "福建     1\n",
       "山东     1\n",
       "Name: area, dtype: int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['area'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
